//
//  HYShortTableViewCell.m
//  KaiJing
//
//  Created by lanou on 16/1/14.
//  Copyright © 2016年 HuangZuCui. All rights reserved.
//

#import "HYShortTableViewCell.h"
#import "UIView+WLFrame.h"
#import <UIButton+WebCache.h>
@implementation HYShortTableViewCell

- (instancetype) initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        //大的图片
        _shortImageButton = [UIButton buttonWithType:(UIButtonTypeSystem)];
        _shortImageButton.frame = CGRectMake(0, 0, kScreenWidth, kScreenHeight /3);
        _shortImageButton.backgroundColor = kRandomClolor;
        [self.contentView addSubview:_shortImageButton];
        
        //标题
        _titleLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, _shortImageButton.bottom + 10, kScreenWidth, 30)];
        [self.contentView addSubview:_titleLabel];
        //_titleLabel.backgroundColor = kRandomClolor;
        _titleLabel.textAlignment = NSTextAlignmentCenter;
        
        //简介
        _synopsisLabel =[[UILabel alloc] initWithFrame:CGRectMake(10, _titleLabel.bottom + 10, kScreenWidth - 20, 60)];
        [self.contentView addSubview:_synopsisLabel];
        //_synopsisLabel.backgroundColor = kRandomClolor;
        _synopsisLabel.textAlignment = NSTextAlignmentCenter;
        _synopsisLabel.numberOfLines = -1;
        _synopsisLabel.font = [UIFont systemFontOfSize:15];
        
         
        //点赞等
        _bottomView = [[CJCellBottomView alloc] initWithFrame:CGRectMake(0, _synopsisLabel.bottom + 15, kScreenWidth, 25)];
        
        
        //点赞
        [_bottomView.praiseButton setImage:[UIImage imageNamed:@"parise_norml"] forState:(UIControlStateNormal)];
        [_bottomView.praiseButton setImage:[UIImage imageNamed:@"parise_select"] forState:(UIControlStateSelected)];
        _bottomView.praiseLabel.text = @"赞";
        //评论
        [_bottomView.commentButton setImage:[UIImage imageNamed:@"comment"] forState:(UIControlStateNormal)];
        _bottomView.commentLabel.text = @"评论";
        
        //更多
        [_bottomView.moreButton setImage:[UIImage imageNamed:@"more"] forState:(UIControlStateNormal)];
        
        [_bottomView.moreButton addTarget:self action:@selector(moreButton:) forControlEvents:(UIControlEventTouchUpInside)];
        [self.contentView addSubview:_bottomView];
        

        
    }
    return self;
}

- (void)moreButton:(UIButton *)button {
    SZLog(@"456456");
}

- (void) setModel:(HYMoreShortModel *)model {
    _model = model;
    NSString *string = [NSString stringWithFormat:@"http://morguo.com/%@",model.image];
    [_shortImageButton sd_setBackgroundImageWithURL:[NSURL URLWithString:string] forState:(UIControlStateNormal)];
    _titleLabel.text = model.subject;
    _synopsisLabel.text = model.intro;
    
}


+ (CGFloat)labelAndCellHeight:(HYMoreShortModel *)model {
    NSDictionary *dic = @{NSFontAttributeName:[UIFont systemFontOfSize:15]};
    CGRect frame = [model.intro boundingRectWithSize:CGSizeMake(kScreenWidth - 20, CGFLOAT_MAX) options:(NSStringDrawingUsesLineFragmentOrigin) attributes:dic context:nil];
    return frame.size.height;
}


- (void)awakeFromNib {
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    
}

@end
